<?php
/**
 * XGPHP 轻量级PHP框架
 * @link http://xgphp.xg3.cn
 * @version 2.0.0
 * @license http://www.apache.org/licenses/LICENSE-2.0
 * @author 讯高科技 <xungaokeji@qq.com>
*/
namespace xg\response;

class Html extends \xg\Response {
	public function fileVersion() {
		$content = $this->content;
		preg_match_all('/(?:href|src)=["\']{1}([^"\']*[\.css|\.js])["\']{1}/is',$content,$matchs);
		$matchs[1]=array_unique($matchs[1]);
		foreach($matchs[1] as $matchi){
			if(substr($matchi,0,1)=='/'){
				$version=@filemtime('.'.$matchi);
			}else{
				$version='';
			}
			if($version){
				$content=str_replace($matchi,$matchi.'?v='.date('YmdHis',$version),$content);
			}
		}
		$this->content = $content;
		return $this;
	}
	public function replace($from,string $to='') {
		if(is_array($from)){
			foreach($from as $k=>$v){
				$this->content = str_replace($k,$v,$this->content);
			}
		}else{
			$this->content = str_replace($from,$to,$this->content);
		}
		return $this;
	}
}
?>